package com.example.demo.common;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//定义切面
@Aspect
@Component
public class UserAspect {
    //定义切点
    @Pointcut("execution(* com.example.demo.controller.UserController.* (..))")
    public void pointcut(){
        System.out.println("hello this is pointcut");
    };

    //定义前置通知
    @Before("pointcut()")
    public void before(){
        System.out.println("执行了前置通知");
    };

    //定义后置通知
    @After("pointcut()")
    public void after() {
        System.out.println("执行了后置通知");
    }

    //环绕通知
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前通知");
        Object ret =  joinPoint.proceed();
        System.out.println("环绕后通知");
        return ret;
    }

    //返回之前通知
    @AfterReturning("pointcut()")
    public void afterReturning() {
        System.out.println("执行return之前的通知");
    }
}
